package cn.jiyun.mapper;

import cn.jiyun.pojo.Project;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface ProjectMapper {
    @Insert("INSERT INTO `building_project`.`project`(`pid`, `pname`, `starttime`, `endtime`, `updatetime`, `did`, `cid`)" +
            " VALUES (null, #{pname}, #{starttime}, #{endtime}, #{updatetime}, NULL, NULL)")
    int add(Project project);

    List<Project> findAll(@Param("pageNum") int pageNum, @Param("pageSize") Integer pageSize, @Param("queryString") String queryString);

    @Select("select count(*) from project ")
    Long getCount();

    @Update("UPDATE `building_project`.`project` SET `pname` = #{pname}, `starttime` = #{starttime}, `endtime` = #{endtime}, `updatetime` = #{updatetime}, `did` = #{did}, `cid` = NULL, `state` = '1' WHERE `pid` = #{pid}")
    int update(Project project);

    @Update("UPDATE project SET did = #{sid}   WHERE  pid = #{id}")
    int update2(@Param("sid") int sid,@Param("id")int id);

    @Delete("delete from  project where pid=#{pid} ")
    int delete(Integer pid);

    @Select("select * from project where pid=#{pid}")
    Project findById(Integer pid);

    @Select("select * from project where state='1' and pid  not in(select p.pid from project p,developer d where p.did=d.did)")
    List<Project> findName();
    @Update("UPDATE `building_project`.`project` SET   `did` = #{sid}  WHERE `state` = '1' and `pid` = #{id}")
    void addDid(@Param("sid") int sid,@Param("id")int id);
}
